package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.BizException;
import com.cskaoyan.shopping.constants.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ITestProductConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ITestProductServiceImpl implements ITestProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    ITestProductConverter productConverter;

    @Override
    public TestProductDetailDto getProductDetail(Long productId) {

        Item item = itemMapper.selectByPrimaryKey(productId);
        if (item == null) {
         // 未找到productI对应的商品
            throw new BizException(ShoppingRetCode.PRODUCT_NOT_EXISTS.getCode(),
                    ShoppingRetCode.PRODUCT_NOT_EXISTS.getMessage());
        }
        TestProductDetailDto testProductDetailDto = productConverter.itemDoToDetailDto(item);

        return testProductDetailDto;
    }
}
